<template>
  <div class="app-container">
    <el-input
      placeholder="输入关键字进行过滤"
      v-model="filterText">
    </el-input>
    <el-tree
      ref="tree2"
      :data="data2"
      :props="defaultProps"
      :filter-node-method="filterNode"
    />
  </div>
</template>

<script>
    import http from "@/api/subject"

    export default {
        name: "list",
        data() {
            return {
                filterText: '',
                data2: [],
                defaultProps: {
                    children: 'children',
                    label: 'label'
                }
            }
        },
        watch: {
            filterText(val) {
                this.$refs.tree2.filter(val);
            }
        },

        methods: {
            filterNode(value, data) {
                console.log(value,data)
                if (!value) return true;
                return data.label.toLowerCase().indexOf(value.toLowerCase()) !== -1;
            }
        },
        created() {
            http.getSubjectList().then(res => {
                this.data2 = res.data
            })
        }
    }
</script>

<style scoped>

</style>
